package com.xiaomazi.edu.controller;

import com.xiaomazi.common.utils.R;
import com.xiaomazi.edu.entity.Video;
import com.xiaomazi.edu.service.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program: llxy-parent
 * @description: 小节控制器
 * @author: 小马子
 * @create: 2023-02-19 20:46
 **/
@RestController
@RequestMapping("/eduservice/video")
public class VideoController {

    @Autowired
    private VideoService videoService;

    @PostMapping("/addVideo")
    public R addVideo(@RequestBody Video video){
        return videoService.save(video) ? R.ok() : R.error();
    }

    @PostMapping("/updateVideo")
    public R updateVideo(@RequestBody Video video){
        return videoService.updateById(video) ? R.ok() : R.error();
    }


    @DeleteMapping("/deleteVideoById/{id}")
    public R deleteVideoById(@PathVariable String id){
        return videoService.deleteVideoById(id);
    }

    @DeleteMapping("/deleteVideoByIds/{id}")
    public R deleteVideoByIds(@PathVariable String id){
        return videoService.deleteVideoById(id);
    }


    @GetMapping("/getVideoById/{id}")
    public R getVideoById(@PathVariable String id){
        return R.ok().data("videoInfo",videoService.getById(id));
    }

}
